package com.heima.model.common.dtos;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.heima.model.common.enums.AppHttpCodeEnum;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class PageResponseResult<T> extends ResponseResult<T> implements Serializable {

    private Long currentPage;
    private Long size;
    private Long total;

    /**
     * 分页响应成功
     *
     * @param page
     * @param <T>
     * @return
     */
    public static <T> PageResponseResult success(IPage page) {
        PageResponseResult responseResult = new PageResponseResult(page.getCurrent(), page.getSize(), page.getTotal());
        responseResult.setData(page.getRecords());
        responseResult.setCode(AppHttpCodeEnum.SUCCESS.getCode());
        return responseResult;
    }

}
